45
How the methods know from which object they are invoked?
This is done by implicitly passing a pointer to the invoking object to the method. This pointer can be accessed within the methods as this.
The definitions of methods setX() and setY() make use of class members _x and _y, respectively.
If invoked by an object, these members are automatically' mapped to the correct object.
void Point::setX(const int val) {
this->_x = val; // Use this to reference invoking object
}
void Point::setY(const int val) {
this->_y = val;
}

| Here we explicitly use the pointer this to explicitly dereference the invoking object. Fortunately, the compiler automatically ``inserts'' these dereferences for class
| members, hence, we really can use the first definitions of setX() and setY(). However, it sometimes make sense to know that there is a pointer this available which
| indicates the invoking object.
| Currently, we need to call the set methods to initialize a point object. However, we would like to initialize the point when we define it. We therefore use special
| methods called constructors.